package my.yuan.ms.rediskafkams.service.impl;

import my.yuan.ms.rediskafkams.mapper.StockMapper;
import my.yuan.ms.rediskafkams.mapper.cache.RedisMapper;
import my.yuan.ms.rediskafkams.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zzMh
 * @Description TODO
 */
@Service
public class StockServiceImpl implements StockService {
    @Autowired
    RedisTemplate<String, Object> redisTemplate;
    @Autowired
    RedisMapper redisMapper;
    //redis减库存，每次减一个
    @Autowired
    StockMapper stockMapper;

    @Override
    public boolean redisMinusStock(Integer commondityId) {
        return redisMapper.minusStock(String.valueOf(commondityId), 1);
    }

    @Override
    public void redisPlusStock(Integer commondityId) {
        redisMapper.plusStock(String.valueOf(commondityId), 1);
    }

    @Override
    @Transactional
    public void mysqlMinusStock(Integer commondityId) {
        stockMapper.minusStockByCommondityId(commondityId);

    }


}
